package com.lanou.pro;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zyj
 * @date 2022年06月11日 14:44
 */
public class Server {
    public static void main(String[] args) {
        ServerSocket server = null;
        List<Socket> list = Collections.synchronizedList(new ArrayList<>());
        ExecutorService service = Executors.newFixedThreadPool(100);
        try {
            server = new ServerSocket(80);
            System.out.println("服务端已经启动，等待客户端连接");
           while (true) {
               Socket socket = server.accept();
               System.out.println("客户端ip：" + socket.getInetAddress() + ":" + socket.getPort());

               ServerHandler handler = new ServerHandler(list,socket);
               service.submit(handler);
           }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
